﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WSAP
{
    /// <summary>
    /// WModelNet拓展方法
    /// </summary>
    public static class WDomainNetExtension
    {
        /// <summary>
        /// 增加梁线荷载
        /// </summary>
        /// <param name="model"></param>
        /// <param name="elementTag"></param>
        /// <param name="gravityLoad"></param>
        /// <returns></returns>
        public static bool AddBeamUniformLoad(this WDomainNet domain, int elementTag,
            double gravityUniformLoad)
        {
            return domain.AddFrameZDistLoad(elementTag, -gravityUniformLoad);
        }

        /// <summary>
        /// 显示警告及错误信息
        /// </summary>
        /// <param name="model"></param>
        public static bool ShowWarningError(this WDomainNet domain)
        {
            //警告及错误信息不存在
            if (domain.GetError() == string.Empty) return true;
            //存在则显示
            Form f = new AnalyzeInfo(domain);
            f.ShowDialog();
            return false;
        }

        /// <summary>
        /// 获得错误信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static string GetError(this WDomainNet domain)
        {
            //初始化
            var error = string.Empty;
            //遍历错误信息
            domain.GetErrors().ForEach(str => error += str + Environment.NewLine);
            return error;
        }

        /// <summary>
        /// 获得节点响应
        /// </summary>
        /// <param name="model"> 分析模型 </param>
        /// <param name="responseType"> 响应类型 </param>
        /// <param name="dof"> 自由度 </param>
        /// <returns></returns>
        public static List<double> GetNodeResponseList(this WDomainNet domain, int nodeTag, NodeResponseEnum responseType, int dof)
        {
            return domain.GetNodeResponseList(nodeTag, (int)responseType, dof);
        }

        #region 梁荷载

        ///// <summary>
        ///// 增加梁线荷载
        ///// </summary>
        ///// <param name="model"></param>
        ///// <param name="elementTag"></param>
        ///// <param name="gravityLoad"></param>
        ///// <returns></returns>
        //public static bool AddBeamTriangularLoad(this WModelNet model, int elementTag,
        //    double gravityMaxLoad, double maxLoadLengthFacotr)
        //{
        //    return model.AddElementLoad(elementTag, (int)ElementLoadEnum.FrameTriangular,
        //        new List<double> { 0, -gravityMaxLoad, maxLoadLengthFacotr });
        //}

        ///// <summary>
        ///// 增加梁线荷载
        ///// </summary>
        ///// <param name="model"></param>
        ///// <param name="elementTag"></param>
        ///// <param name="gravityLoad"></param>
        ///// <returns></returns>
        //public static bool AddBeamTrapezoidLoad(this WModelNet model, int elementTag,
        //    double gravityMaxLoad, double maxLoadLengthFacotrI, double maxLoadLengthFacotrJ)
        //{
        //    return model.AddElementLoad(elementTag, (int)ElementLoadEnum.FrameTrapezoid,
        //        new List<double> { 0, -gravityMaxLoad, maxLoadLengthFacotrI, maxLoadLengthFacotrJ });
        //}

        ///// <summary>
        ///// 增加梁线荷载
        ///// </summary>
        ///// <param name="model"></param>
        ///// <param name="elementTag"></param>
        ///// <param name="gravityLoad"></param>
        ///// <returns></returns>
        //public static bool AddBeamPointLoad(this WModelNet model, int elementTag,
        //    double gravityLoad, double loadLengthFacotr)
        //{
        //    return model.AddElementLoad(elementTag, (int)ElementLoadEnum.FramePoint,
        //        new List<double> { 0, -gravityLoad, 0, loadLengthFacotr });
        //}

        #endregion

        #region Error Warning

        ///// <summary>
        ///// 获得警告信息
        ///// </summary>
        ///// <param name="model"></param>
        ///// <returns></returns>
        //public static string GetWarning(this WModelNet model)
        //{
        //    //初始化
        //    var error = string.Empty;
        //    //遍历错误信息
        //    model.GetWarnings().ForEach(str => error += str + Environment.NewLine);
        //    return error;
        //}

        #endregion

    }
}
